package ift585.tp2;


public class Message {
	
	private byte [] payload;


	private Byte messageType;
	private String sender;
	private String nextHop;
	private int port;
	private String receiver;
	
	public Message(String receiverAddress, String nextHop, String senderAddress, Byte typeOfMessage, byte [] dataToSend){
		this.receiver = receiverAddress;
		this.sender = senderAddress;
		this.nextHop = nextHop;
		this.messageType = typeOfMessage;
		this.payload = dataToSend;
		
		String [] addressAndPort = receiverAddress.split(":");
		port = Integer.valueOf(addressAndPort[1]);
	}
	
	public String getSender() {
		return sender;
	}	
	
	public String getNextHop() {
		return nextHop;
	}
	
	public void setNextHop(String nextHop) {
		this.nextHop = new String(nextHop);
	}

	public String getReceiver() {
		return receiver;
	}

	
	public byte[] getPayload() {
		return payload;
	}

	
	public String getStringPayload() {
		StringBuilder builder = new StringBuilder(); 
		for(int i = 0; i < payload.length ; i++)
			builder.append((char)payload[i]);
		return builder.toString();
	}

	public Byte getMessageType() {
		return messageType;
	}

	public void setMessageType(Byte messageType) {
		this.messageType = messageType;
	}
}